package cn.crce.cloud9.comp;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 * @author OnCloud9
 * @description
 * @project NRCE-TEST
 * @date 2022年09月13日 下午 09:36
 */
public class Case37 implements ActionListener {
    public static void main(String args[]) {
        Case37 tb = new Case37();
        //*********Found********
        JFrame f = new JFrame("Button Test");
        f.setSize(200, 100);
        f.setLayout(new FlowLayout(FlowLayout.CENTER));

        JButton b = new JButton("Press the Button!");  /////JButton
        //*********Found********
        b.addActionListener(tb);

        //*********Found********
        f.add(b);
        f.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        f.setVisible(true);
    }

    //*********Found********
    public void actionPerformed(ActionEvent e) {
        JFrame fr = new JFrame("An Other");
        fr.setBackground(Color.green);
        fr.add(new JLabel("This frame shows when " + "pressing the button in Button Test"));
        fr.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        fr.pack();
        fr.setVisible(true);
    }
}
